﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.tutorial.chapter {
    import flash.utils.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.constants.*;
    import net.wooga.pets.controllers.startup.*;
    import net.wooga.pets.views.tutorial.*;

    public class TutorialKitchenMediator extends TutorialMediator {

        private var _localMapping:Dictionary;

        public function TutorialKitchenMediator():void{
            this._localMapping = new Dictionary();
            this._localMapping[TutorialModel.KIOSK_START_TUTORIAL] = this.onBuildKitchenTutorial;
            this._localMapping[TutorialModel.KIOSK_CLICK_ON_SHOP] = this.onClickShopForKitchen;
            this._localMapping[TutorialModel.KIOSK_CHOOSE_ROOM] = this.onChooseKiosk;
            this._localMapping[TutorialModel.KIOSK_PLACE_ROOM] = this.onPlaceKiosk;
            this._localMapping[TutorialModel.KIOSK_FINISH_TUTORIAL] = this.onFinish;
        }
        override public function onRegister():void{
            super.onRegister();
        }
        override protected function onStateChange(_arg1:GameEvent=null):void{
            super.onStateChange(_arg1);
            var _local2:Function = this._localMapping[tutorialModel.state];
            if (_local2 != null){
                _local2();
            };
        }
        public function onBuildKitchenTutorial():void{
            eventMap.mapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            tutorial.showClickBlocker();
            tutorial.hideSpotlight();
            dispatch(new WindowsMainViewUpdateEvent(WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS));
        }
        public function onClickShopForKitchen():void{
            roomSlotsModel.tempAvailableRoomSlots = 1;
            dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
            centerGameView(GameViewModel.SCALE_4X4);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_OPEN_CUSTOMIZE_MENU, TutorialModel.KIOSK_CHOOSE_ROOM);
            dispatch(new InfoEvent(EventConstants.SELECT_SHOP_CATEGORY, null, {category:"rooms"}));
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_clickshopforkiosk");
            focusShopButton();
        }
        public function onChooseKiosk():void{
            roomSlotsModel.tempAvailableRoomSlots = 1;
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, false));
            centerGameView(GameViewModel.SCALE_4X4);
            eventMap.unmapListener(eventDispatcher, EventConstants.BUBBLE_CLOSED, mapBubbleClosed);
            mapEvent(EventConstants.ON_START_DRAGGING_CUSTOMIZE_ITEM, TutorialModel.KIOSK_PLACE_ROOM);
            eventMap.mapListener(eventDispatcher, EventConstants.TRY_TO_CANCEL_BUILDMODE, mapTryToCancel);
            if (tutorialModel.kioskShopItemPosition){
                sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_choosekiosk");
                tutorial.showFocusArrow((tutorialModel.kioskShopItemPosition.x - 10), (tutorialModel.kioskShopItemPosition.y - 170));
                tutorial.showClickBlocker((tutorialModel.kioskShopItemPosition.x + 30), (tutorialModel.kioskShopItemPosition.y + 30), 0.3);
                tutorial.showSpotlight((tutorialModel.kioskShopItemPosition.x + 30), (tutorialModel.kioskShopItemPosition.y + 30), 0.5);
            } else {
                tutorial.hideFocusArrow();
                tutorial.showClickBlocker();
                tutorial.hideSpotlight();
                setTimeout(this.onChooseKiosk, 1000);
            };
        }
        public function onPlaceKiosk():void{
            mapEvent(EventConstants.CREATE_ROOM, TutorialModel.KIOSK_FINISH_TUTORIAL);
            sunModel.simpleMessageWithoutHide = languageModel.getTextByKey("general_tutorial_placekiosk");
            tutorial.hideFocusArrow();
            tutorial.hideClickCatcher();
            tutorial.hideSpotlight();
            roomSlotsModel.tempAvailableRoomSlots = 0;
            _kitchenBuilt = true;
        }
        public function onFinish():void{
            roomSlotsModel.tempAvailableRoomSlots = 0;
            dispatch(new InfoEvent(EventConstants.SET_BUILD_CANCELATION, null, true));
            onRemoveOverlay();
            gameStateModel.state = GameStateModel.STATE_GAME_RUNNING;
            tutorialModel.kioskTutorialActive = false;
            if (tutorialModel.fountainTutorialPending){
                tutorialModel.state = TutorialModel.FOUNTAIN_WELCOME_ELDER;
                tutorialModel.fountainTutorialPending = false;
            };
            enableControls();
        }

    }
}//package net.wooga.pets.views.tutorial.chapter 
